IPHONE_IP=192.168.0.3
#IPHONE_IP=169.254.75.77
VERSION=1.6
CC=/usr/local/bin/arm-apple-darwin-gcc
AS=/usr/local/bin/arm-apple-darwin-as
LD=$(CC) 
LDFLAGS = -lobjc \
          -framework CoreFoundation \
          -framework Foundation \
          -framework UIKit \
          -framework LayerKit \
          -framework CoreGraphics \
          -framework GraphicsServices \
          -framework CoreSurface \
          -framework CoreAudio \
          -larmfp
CFLAGS	:=	-g -Wall -O3 \
			-ffast-math

default: all

all: App

App: Waves WavesDaemon
	mkdir -p bin
	mkdir -p bin/Applications
	mkdir -p bin/Applications/Waves.app
	chmod 0755 bin/Applications/Waves.app
	mkdir -p bin/Applications/Waves.app/daemon
	chmod 0755 bin/Applications/Waves.app/daemon
	mv Waves bin/Applications/Waves.app
	chmod 0755 bin/Applications/Waves.app/Waves
	mv WavesDaemon bin/Applications/Waves.app/daemon
	chmod 0755 bin/Applications/Waves.app/daemon/WavesDaemon
	cp Resources/Button.png Resources/com.gnese.wavesdaemons.plist bin/Applications/Waves.app/daemon
	cp Resources/InfoDaemon.plist bin/Applications/Waves.app/daemon/Info.plist
	cp Resources/Bear.jpg Resources/Clownfish.jpg Resources/Bubbles.jpg Resources/Default.png Resources/icon.png bin/Applications/Waves.app
	cp Resources/InfoApp.plist bin/Applications/Waves.app/Info.plist
	

Waves: main.o App.o ConfigView.o WaveTypeView.o WaveSpeedView.o MainView.o Config.o draw.o 
	$(LD) $(LDFLAGS) -v -o $@ $^

WavesDaemon: maindaemon.o AppDaemon.o MainView.o Button.o Config.o draw.o
	$(LD) $(LDFLAGS) -v -o $@ $^
	
%.o: %.m
	$(CC) -c $(CFLAGS) $(CPPFLAGS) $< -o $@
	
%.o: %.c
	$(CC) -c $(CFLAGS) $(CPPFLAGS) $< -o $@

clean:
	rm -rf *.o bin
	
install: App
	scp -r bin/Applications root@$(IPHONE_IP):/
	# ssh -t root@$(IPHONE_IP) /Applications/Waves.app/Waves
run: install
	ssh -t root@$(IPHONE_IP) /Applications/Waves.app/Waves
	
package: App
	@rm -rf waves-$(VERSION).zip
	@cd bin/Applications;zip -o ../../waves-$(VERSION).zip -r Waves.app
	@date '+%s'
	@ls -la waves-$(VERSION).zip
	@md5sum.exe waves-$(VERSION).zip
	@mv waves-$(VERSION).zip release/
	
